<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>渐变流水灯特效</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .outer-container {
            display: flex;
            justify-content: center;
            align-items: center;
            border: 2px solid #333;
            padding: 20px;
            border-radius: 10px;
            background-color: #fff;
        }
        .container {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .box {
            width: 30px;
            height: 30px;
            margin: 3px;
            background-color: #3498db;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="outer-container">
        <div class="container" id="container">
            <!-- 20个方格 -->
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
            <div class="box"></div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const boxes = document.querySelectorAll('.box');
            let current = 0;

            function lightUp() {
                boxes.forEach((box, index) => {
                    let distance = (index - current + boxes.length) % boxes.length;
                    let opacity = 1 - distance * 0.05;
                    box.style.backgroundColor = `rgba(231, 76, 60, ${opacity})`;
                });
                current = (current + 1) % boxes.length;

                // Check if we have completed one full cycle
                if (current === 0) {
                    setTimeout(lightUp, 500); // Add delay before starting next cycle
                } else {
                    setTimeout(lightUp, 100); // Adjust this delay for smoother transition
                }
            }

            setTimeout(lightUp, 500);
        });
    </script>
</body>
</html>
